home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2006 October / wn148cd2.iso / Windows / S'informer / Copernic Desktop Search / copernicdesktopsearchfr.exe / $R0 / 1033 / RC_DATA / RSSJAVASCRIPT < prev    next >
Text File  |  2006-05-31  |  8KB  |  261 lines

  1. /****************************************************************************
  2. * Copyright (c) 2006, Copernic Technologies Inc.
  3. ****************************************************************************/
  4.  
  5. /****************************************************************************
  6. *  Summary :
  7. *    Function used by rss xslt.
  8. *  Description:
  9. *    This unit contains the functions related to the rss feed.
  10. *  Author:
  11. *    Copernic Technologies Inc.
  12. ****************************************************************************/
  13.  
  14. var c_ImageNewsDown = "arrow-news-down.gif";
  15. var c_ImageNews = "arrow-news.gif";
  16. var c_ImageFeed = "arrow.gif";
  17. var c_ImageFeedDown = "arrow-down.gif";
  18. var c_ComleteNewsId = "CompleteNews";
  19. var c_NewsDescId = "News_";
  20. var c_NewsImageId = "NewsImg_";
  21. var c_CookieLimitNewsNumber = "LimitNewsNumber";
  22. var c_FeedBodyId = "FeedBody_";
  23. var c_FeedImgId = "FeedImg_";
  24. var c_FeedHRId = "HR_";
  25. var c_CookieExpandState = "ExpandState"
  26. var c_ContentDiv = "main-content-div";
  27.  
  28. /*
  29. *  Summary:
  30. *    Restore saved number of items to display by feed.
  31. */
  32. function RestorePreferences(){
  33.     var SavedCookie = getCookie(c_CookieLimitNewsNumber);
  34.     if (SavedCookie !== null){
  35.         if(IsNumeric(SavedCookie)){
  36.             document.getElementById('ComboNbrItem').value = SavedCookie;
  37.             LimitNewsNumber(SavedCookie);            
  38.         }
  39.     }else{
  40.         LimitNewsNumber(document.getElementById('ComboNbrItem').value);
  41.     }
  42.     var SavedCookieExpand = getCookie(c_CookieExpandState);
  43.     if (SavedCookieExpand !== null){
  44.         if(SavedCookieExpand == 0){        
  45.             ExpandAllItems(0);
  46.         }
  47.         if(SavedCookieExpand == 1){
  48.             ExpandAllItems(1);
  49.         }
  50.     }
  51.     // Display content
  52.     document.getElementById(c_ContentDiv).style.display = "inline";
  53. }
  54.  
  55. /*
  56. *  Summary:
  57. *    Validate if a string is numeric.
  58. *  Parameter:
  59. *    p_Text: Text to validate.
  60. *  Returns:
  61. *    Return true if all char are numeric, false otherwise.
  62. */
  63. function IsNumeric(p_Text)
  64. {
  65.     var ValidChars = "0123456789";
  66.     var IsNumber=true;
  67.     var Char;
  68.     for (i = 0; i < p_Text.length && IsNumber == true; i++) 
  69.     { 
  70.         Char = p_Text.charAt(i); 
  71.         if (ValidChars.indexOf(Char) == -1) 
  72.         {
  73.             IsNumber = false;
  74.         }
  75.     }
  76. return IsNumber;   
  77. }
  78.  
  79. /*
  80. *  Summary:
  81. *    Limit the maximum of news displayed by feed.
  82. *    This automatically saved this value to a cookie. 
  83. *  Parameter:
  84. *    p_Value: Maximum number of news to display.
  85. */
  86. function LimitNewsNumber(p_Value){
  87.     var AllDiv = document.getElementsByTagName("div");
  88.     var UnderscorePos;
  89.     for (var i = 0; i < AllDiv.length; i++)
  90.     {
  91.         if (AllDiv[i].id.substring(0,c_ComleteNewsId.length) == c_ComleteNewsId){
  92.           UnderscorePos = AllDiv[i].id.indexOf('_');
  93.           if(parseInt(AllDiv[i].id.substring(12,UnderscorePos)) > p_Value){
  94.             AllDiv[i].style.display = "none";                        
  95.           }
  96.           else{
  97.             AllDiv[i].style.display = "inline";            
  98.           }
  99.         }        
  100.     }
  101.     //save this in a cookie
  102.     var ExpireDate = new Date();
  103.     var today = new Date()
  104.     // valid for 1 year
  105.     ExpireDate.setTime(today.getTime() + 24*365*3600000);
  106.     setCookie(c_CookieLimitNewsNumber,p_Value,ExpireDate,null,null,0);        
  107. }
  108.  
  109. /*
  110. *  Summary:
  111. *    Show/Hide all news text(expand/colapse).
  112. *  Parameter:
  113. *    p_ShowItem: Boolean 0=hide 1=show
  114. */
  115. function ExpandAllItems(p_ShowItem){
  116.     var AllDiv = document.getElementsByTagName("div");
  117.     for (var i = 0; i < AllDiv.length; i++)
  118.     {
  119.         if (AllDiv[i].id.substring(0,c_NewsDescId.length) == c_NewsDescId){
  120.           if (p_ShowItem){
  121.             AllDiv[i].style.display = "inline";            
  122.           }else{
  123.             AllDiv[i].style.display = "none";            
  124.           }
  125.         }
  126.         else if ((AllDiv[i].id.substring(0,c_FeedBodyId.length) == c_FeedBodyId) && p_ShowItem){
  127.           AllDiv[i].style.display = "inline";
  128.         }
  129.         else if ((AllDiv[i].id.substring(0,c_FeedHRId.length) == c_FeedHRId) && p_ShowItem){
  130.           AllDiv[i].style.display = "inline";
  131.         }
  132.     }
  133.     var AllArrow = document.getElementsByTagName("img");
  134.     for (var j = 0; j < AllArrow.length; j++)
  135.     {
  136.         if (AllArrow[j].id.substring(0,c_NewsImageId.length) == c_NewsImageId){
  137.           if (p_ShowItem){
  138.             AllArrow[j].src = c_ImageNewsDown;
  139.           }else{
  140.             AllArrow[j].src = c_ImageNews;
  141.           }
  142.         }
  143.         else if ((AllArrow[j].id.substring(0,c_FeedImgId.length) == c_FeedImgId) && p_ShowItem){
  144.             AllArrow[j].src = c_ImageFeedDown;
  145.         }
  146.     }
  147.     //save this in a cookie
  148.     var ExpireDate = new Date();
  149.     var today = new Date()
  150.     // valid for 1 year
  151.     ExpireDate.setTime(today.getTime() + 24*365*3600000);
  152.     setCookie(c_CookieExpandState,p_ShowItem,ExpireDate,null,null,0);    
  153. }
  154.  
  155. /*
  156. *  Summary:
  157. *    Hide or show a specific section.
  158. *  Parameter:
  159. *    p_id: Id number of the section.
  160. *    p_Section: Section type. (FEED or NEWS)
  161. */
  162. function toggle(p_Id, p_Section) {
  163.     if(p_Section == "FEED"){
  164.         var target_div = c_FeedBodyId + p_Id;
  165.         var target_img = c_FeedImgId + p_Id;
  166.         var div_handle = document.getElementById(target_div);
  167.         var hr_handle = document.getElementById(c_FeedHRId + p_Id);
  168.         if(div_handle.style.display == "none"){
  169.             document.getElementById(target_img).src = c_ImageFeedDown;
  170.             div_handle.style.display = "inline";
  171.             hr_handle.style.display = "inline";
  172.         }
  173.         else{      
  174.             document.getElementById(target_img).src = c_ImageFeed;
  175.             div_handle.style.display = "none";
  176.             hr_handle.style.display = "none";
  177.         }    
  178.     }
  179.     else if(p_Section == "NEWS"){
  180.         var target_div = c_NewsDescId + p_Id;
  181.         var target_img = c_NewsImageId + p_Id;
  182.         var div_handle = document.getElementById(target_div);
  183.         if(div_handle.style.display == "none"){
  184.             document.getElementById(target_img).src = c_ImageNewsDown;
  185.             div_handle.style.display = "inline";
  186.         }
  187.         else{      
  188.             document.getElementById(target_img).src = c_ImageNews;
  189.             div_handle.style.display = "none";
  190.         }
  191.     }
  192. }
  193.  
  194. /*
  195. *  Summary:
  196. *    Hide p_DivToHide and show p_DivToShow.
  197. *  Parameter:
  198. *    p_DivToHide: Id of div section to hide.
  199. *    p_DivToShow: Id of div section to show.
  200. */
  201. function ShowMore(p_DivToHide, p_DivToShow) {
  202.     document.getElementById(p_DivToHide).style.display = "none";
  203.     document.getElementById(p_DivToShow).style.display = "inline";
  204. }
  205.  
  206. /****************************************************************
  207.           COOKIE FUNCTIONS
  208. *****************************************************************/
  209. /*
  210. *  Summary:
  211. *    Sets a cookie.
  212. *  Parameters:    
  213. *    p_name: Name of the cookie.
  214. *    p_value: Value of the cookie.
  215. *    p_expires: Expiration date of the cookie.
  216. *      (defaults to end of current session)
  217. *    [p_path]: path for which the cookie is valid.
  218. *      (defaults to path of calling document)
  219. *    [p_domain]: domain for which the cookie is valid.
  220. *     (defaults to domain of calling document)
  221. *    [p_secure]: Boolean value indicating if the cookie transmission requires
  222. *      a secure transmission.
  223. *  Notes: 
  224. *    An argument defaults when it is assigned null as a placeholder
  225. *    A null placeholder is not required for trailing omitted arguments
  226. */
  227.  
  228. function setCookie(p_name, p_value, p_expires, p_path, p_domain, p_secure) {
  229.   var NewCookie = p_name + "=" + escape(p_value) +
  230.       ((p_expires) ? "; expires=" + p_expires.toGMTString() : "") +
  231.       ((p_path) ? "; path=" + p_path : "") +
  232.       ((p_domain) ? "; domain=" + p_domain : "") +
  233.       ((p_secure) ? "; secure" : "");
  234.   document.cookie = NewCookie;
  235. }
  236.  
  237.  
  238. /*
  239. *  Summary:
  240. *    Gets a cookie.
  241. *  Parameter:
  242. *    p_name: Name of the cookie to read.
  243. *
  244. *  Return string containing value of specified cookie or null
  245. *  if cookie does not exist
  246. */
  247.  
  248. function getCookie(p_name) {
  249.   var DocumentCookie = document.cookie;
  250.   var Prefix = p_name + "=";
  251.   var BeginPosition = DocumentCookie.indexOf("; " + Prefix);
  252.   if (BeginPosition == -1) {
  253.     BeginPosition = DocumentCookie.indexOf(Prefix);
  254.     if (BeginPosition != 0) return null;
  255.   } else
  256.     BeginPosition += 2;
  257.   var EndPosition = DocumentCookie.indexOf(";", BeginPosition);
  258.   if (EndPosition == -1)
  259.     EndPosition = DocumentCookie.length;
  260.   return unescape(DocumentCookie.substring(BeginPosition + Prefix.length, EndPosition));
  261. }